<?php
session_start();
require_once( 'leave_db.php' );
 
$type = new M_leave();
$user_id = $_SESSION['userid'];

if (isset($_POST['m'])  &&  $_POST['m']!=""){

    if ($_POST['m']== 'load'){
     
			$data = array();
        
    
        $arr = array('aaData'=>$data);
        
        echo json_encode($arr);
      
    }else if ($_POST['m']=='add'){
        $ar = array();
		$ar['date_from']="";
		if ($_POST['df'] !=''){
			list($d,$m,$y) = split('/', $_POST['df']);
			$ar['date_from']= $y.'/'.$m.'/'.$d;
		}
		$ar['date_to']="";
		if ($_POST['dt'] !=''){
			list($d,$m,$y) = split('/', $_POST['dt']);
			$ar['date_to']= $y.'/'.$m.'/'.$d;
		}
		
 
		$ar['reason']=  $_POST['reason'];
		$ar['type']=  $_POST['leave'];
		$ar['eid']=  $user_id;
		 
		$ar['createdate'] =date( "Y/m/d H:i:s" );
		$ar['createby'] = $user_id;
		 
		$id=$type->InsertData($ar);
		
    } 
	else if ($_POST['m']=='del'){
         $id=$_POST['id'];
		 $type->deleData($id);
		 
    }/// Age Criteria
	    
}else{
	if (isset($_GET['m']) && $_GET['m'] !="" ){
		if($_GET['m']=='ly')
			echo json_encode( $type->getLeave());
		else if($_GET['m']=='l')
			echo json_encode( $type->getLeave('Y'));
		 
	}
}
 
?>